home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Documentation / Code Examples from Docs / langguid / chap_06 / xmpl_11.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  1.3 KB  |  51 lines  |  [TEXT/ttxt]

  1. --<<<
  2. -- Kaleida Labs, Inc.
  3. -- Field Guide to the ScriptX Language
  4. -- chapter 6, example 11
  5.  
  6. -- specializing getters and setters for inherited variables
  7.  
  8. -- VerbosePresenter example
  9. class VerbosePresenter (TwoDPresenter)
  10.     instance variables
  11.         _x, _y
  12.     instance methods
  13.     method xSetter self value -> (
  14.         self._x := value
  15.         local val
  16.         format debug "x is stored internally as %* " value @normal
  17.         format debug "but displayed as %*\n" (val := round value) @normal
  18.         nextMethod self val
  19.     )
  20.     method ySetter self value -> (
  21.         self._y := value
  22.         local val
  23.         format debug "y is stored internally as %* " value @normal
  24.         format debug "but displayed as %*\n" (val := round value) @normal
  25.         nextMethod self val
  26.     )
  27. end
  28.  
  29. method xGetter self {class VerbosePresenter} -> (
  30.     local value := nextMethod self
  31.     format debug "x is displayed as %* " value @normal
  32.     format debug "but stored internally as %*\n" self._x @normal
  33.     return value
  34. )
  35. method yGetter self {class VerbosePresenter} -> (
  36.     local value := nextMethod self
  37.     format debug "y is displayed as %* " value @normal
  38.     format debug "but stored internally as %*\n" self._y @normal
  39.     return value
  40. )
  41.  
  42. -- create an instance of VerbosePresenter and assign values to x and y
  43. -- to test our new setter methods
  44. global vp := new VerbosePresenter
  45. vp.x := 3.33
  46. vp.y := 6.66
  47.  
  48. -- now test the new getter methods
  49. vp.x
  50. vp.y
  51. -->>>